﻿using MailDAL;
using MailTool.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MailTool
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string username = txtUserName.Text.Trim();
            string password = DEncrypt.md5(txtPassword.Text.Trim(), 32); 
            if (!ValidateUser(username,password))
            {
                JsUtil.Alert("输入的会员账号或密码不正确！", this.Page);
            }
            else
            {
                Response.Redirect("Index.aspx");
            }
        }

        private bool ValidateUser(string userName, string password)
        {
            UnitOfWork unitOfWork=new UnitOfWork();
            MailModel.User user=unitOfWork.UserRepository.Get(p=>p.UserName==userName,null,1).FirstOrDefault();
            if (user != null)
            {
                SessionState.CurrentUser = user;
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}